package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.BasEmployee;
import com.wuliu.system.service.IBasEmployeeService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 员工资料Controller
 *
 * @author realue
 * @date 2023-10-24
 */
@Api(tags = {"员工管理控制器"})
@RestController
@RequestMapping("/system/employee")
public class BasEmployeeController extends BaseController {
    @Resource
    private IBasEmployeeService basEmployeeService;

    /**
     * 查询员工资料列表
     */
    @ApiOperation(value = "查询员工")
    @PreAuthorize("@ss.hasPermi('system:employee:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasEmployee basEmployee) {
        basEmployee.setSysAccount(getSysAccount());
        startPage();
        List<BasEmployee> list = basEmployeeService.selectBasEmployeeList(basEmployee);
        return getDataTable(list);
    }

    /**
     * 导出员工资料列表
     */
    @ApiOperation(value = "导出员工")
    @PreAuthorize("@ss.hasPermi('system:employee:export')")
    @Log(title = "员工资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasEmployee basEmployee) {
        basEmployee.setSysAccount(getSysAccount());
        List<BasEmployee> list = basEmployeeService.selectBasEmployeeList(basEmployee);
        ExcelUtil<BasEmployee> util = new ExcelUtil<BasEmployee>(BasEmployee.class);
        util.exportExcel(response, list, "员工资料数据");
    }

    /**
     * 获取员工资料详细信息
     */
    @ApiOperation(value = "员工详细")
    @PreAuthorize("@ss.hasPermi('system:employee:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basEmployeeService.selectBasEmployeeById(id));
    }

    /**
     * 新增员工资料
     */
    @ApiOperation(value = "新增员工")
    @PreAuthorize("@ss.hasPermi('system:employee:add')")
    @Log(title = "员工资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated BasEmployee basEmployee) {
        basEmployee.setSysAccount(getSysAccount());
        basEmployee.setCreateBy(getUsername());
        return toAjax(basEmployeeService.insertBasEmployee(basEmployee));
    }

    /**
     * 修改员工资料
     */
    @ApiOperation(value = "修改员工")
    @PreAuthorize("@ss.hasPermi('system:employee:edit')")
    @Log(title = "员工资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated BasEmployee basEmployee) {
        basEmployee.setUpdateBy(getUsername());
        return toAjax(basEmployeeService.updateBasEmployee(basEmployee));
    }

    /**
     * 删除员工资料
     */
    @ApiOperation(value = "删除员工")
    @PreAuthorize("@ss.hasPermi('system:employee:remove')")
    @Log(title = "员工资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basEmployeeService.deleteBasEmployeeByIds(ids));
    }
}
